#!/usr/bin/env python

# This script ...

import numpy as np
import pylab as pl
import os.path as osp
import sys
from matplotlib.font_manager import FontProperties as FP

	
if __name__ == '__main__':

	# Font fix
	fp = FP()
	fp.set_size('small')

	# Prepare figure 
	fig = pl.figure() # Setting aspect ratio , figsize=[10,4]
	ax1 = fig.add_subplot(111)

	### Generate Dotted net ###

	dots_x=[]
	dots_y=[]
	nb_y_dots=200
	nb_x_dots=200

	for j in range(0,nb_x_dots):
		for k in range(0,nb_y_dots):
			dots_x.append(j)

	for j in range(0,nb_x_dots):
		for j in range(0,nb_y_dots):
			dots_y.append(j)

	ax1.plot(dots_x,dots_y,linestyle='None',marker='o',color='black',markersize=3.2)

	### Generate I decode region ###

	I_block_length=3 # Nb of packets in I layer(most important layer
	I_dec_bound=[] # Decoding boundary for I layer
		
	for j in range(0,nb_x_dots):
		I_dec_bound.append(I_block_length)

	ax1.plot(range(0,nb_x_dots),I_dec_bound,label='Layer 1 decode bound')

	### Generate IP decode region (1) ###

		#	P_block_length=7+I_block_length # Nb of packets in I layer(most important layer
		#	P_dec_bound_y=[] # Decoding boundary for I layer
		#	P_dec_bound_x=[]
		#		
		#	for j in range(0,nb_x_dots):
		#		P_dec_bound_y.append(j)
		#		P_dec_bound_x.append(P_block_length)

		#	ax1.plot(P_dec_bound_x,P_dec_bound_y)

	### Generate IP decode region (2) ###

	# Manually
	IP_dec_bound_x=[7,7,7,7,7,7,7,7,7,7,7,7,7,8,9,10,11,12,13,14]
	IP_dec_bound_y=[15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,0,0,0,0]

	ax1.plot(IP_dec_bound_x,IP_dec_bound_y,label='Layer 1 & 2 decode bound')

	### Plot annotation ###

	ax1.set_xlabel('Nb of received layer 2 packets that increased rank [-]')
	ax1.set_ylabel('Nb of received layer 1 packets that increased rank [-]')
	ax1.legend(prop=fp)
	ax1.grid(True,which='both')
	x_scope=12 # What to view in plot, x-axis
	y_scope=12 # What to view in plot, y-axis
	pl.xlim(0,x_scope)
	pl.ylim(0,y_scope)
	ax1.set_xticks(range(0,x_scope+1))
	ax1.set_yticks(range(0,y_scope+1))

	# Save figure
	workingdir = osp.abspath('../../rapport')
	pl.savefig(workingdir+'/figs/dec_region_ew.eps')

	sys.exit()




